package com.jzr.bedside.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.bedside.db1.model.TDoctor;
import com.jzr.bedside.db1.service.TDoctorService;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.U;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "医生接口")
@RestController
@RequestMapping("/api/doctor")
public class DoctorController {
    @Autowired
    private TDoctorService doctorService;

    @ApiOperation("获取医生列表")
    @GetMapping("/get")
    public Result<List<TDoctor>> get(@ApiParam("医生查询参数") TDoctor record){
        if(record == null){
            return Result.fail("参数不能为空");
        }
        if(U.isBlank(record.getDeptCode())){
            return Result.fail("deptCode不能为空");
        }
        QueryWrapper<TDoctor> qw = new QueryWrapper<>();
        qw.orderByAsc("dept_code","name");
        if(U.isNotBlank(record.getDeptCode())) {
            qw.eq(TDoctor.DeptCode_,record.getDeptCode());
        }
        if(U.isNotBlank(record.getCode())){
            qw.eq(TDoctor.Code_,record.getCode());
        }
        List<TDoctor> list = doctorService.list(qw);
        return Result.success("成功",list,list==null ? 0:list.size());
    }

}
